import os
from google.appengine.ext.webapp import template
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app

class Redirect(webapp.RequestHandler):
    def get(self):
        self.redirect("https://sites.google.com/a/essilor.fr/great-labs-benchmarking/", True)
        
class LabDashboard(webapp.RequestHandler):
    def get(self):
        if users.get_current_user():
            template_values = {
            'user': users.get_current_user()
            }
            path = os.path.join(os.path.dirname(__file__), 'lab-dashboard.html')
            self.response.out.write(template.render(path, template_values))
        else:
            self.redirect(users.create_login_url(self.request.uri))
            
class GlobalDashboard(webapp.RequestHandler):
    def get(self):
        if users.get_current_user():
            template_values = {
            'user': users.get_current_user()
            }
            path = os.path.join(os.path.dirname(__file__), 'global-dashboard.html')
            self.response.out.write(template.render(path, template_values))
        else:
            self.redirect(users.create_login_url(self.request.uri))
        
application = webapp.WSGIApplication([('/', Redirect),
                                      ('/lab-dashboard', LabDashboard),
                                      ('/global-dashboard', GlobalDashboard)
                                      ], debug=True)


def main():
    run_wsgi_app(application)

if __name__ == "__main__":
    main()
